﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using Entity;

namespace Common.Background.Data
{
    /// <summary>
    /// Background数据库基础操作对象
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class BackgroundRepository<TEntity> : BackgroundRepositoryBase, IBackgroundRepository<TEntity> where TEntity : EntityBase
    {
        #region IRepository<TEntity> 成员

        public void Update(TEntity entity)
        {
            base.UpdateEntity(entity);
        }

        public void Update(IList<TEntity> list)
        {
            base.UpdateEntity(list.Cast<EntityBase>().ToList());
        }

        public void Insert(TEntity entity)
        {
            base.InsertEntity(entity);
        }

        public void Insert(IList<TEntity> list)
        {
            base.InsertEntity(list.Cast<EntityBase>().ToList());
        }

        public TEntity InsertGetIDENTITY(TEntity entity)
        {
            base.InsertEntity(entity);
            return this.Find(entity.PrimaryKey);
        }

        public void Delete(TEntity entity)
        {
            base.DeleteEntity(entity);
        }

        public void Delete(IList<TEntity> list)
        {
            base.DeleteEntity(list.Cast<EntityBase>().ToList());
        }

        public IQueryable<TEntity> GetModel()
        {
            return base.GetEntities<TEntity>();
        }

        public TEntity Find(params object[] keyValues)
        {
            return base.GetEntity<TEntity>(keyValues);
        }

        #endregion
    }
}
